//
//  EleventCell.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/14.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class EleventCell: UICollectionViewCell {
    
    fileprivate var _imgView:UIImageView!;
    fileprivate var _titleLb:UILabel!;
    
    public var dataDic:[String:AnyObject]? {
        didSet {
            self.onChangeUIForData();
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame:frame);
        
        _imgView = UIImageView(frame: self.bounds);
        _imgView.backgroundColor = .clear;
        _imgView.contentMode = .scaleAspectFit;
        self.addSubview(_imgView);
        
        _titleLb = UILabel(frame: CGRect(x: 0, y: self.frame.height-20, width: self.frame.width, height: 20));
        _titleLb.backgroundColor = .clear;
        _titleLb.textAlignment = .center;
        _titleLb.textColor = .white;
        _titleLb.font = UIFont.systemFont(ofSize: 16);
        _titleLb.numberOfLines = 0;
        self.addSubview(_titleLb);
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:Actions
    fileprivate func onChangeUIForData() {
        self.setNeedsLayout();
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
        
        if self.dataDic != nil {
            _imgView.image = UIImage(named: (self.dataDic!["img"] as! String));
            _titleLb.text = (self.dataDic!["title"] as! String);
        }
    }
}
